#pragma once

#include <vector>
#include <memory>
#include <stdexcept>
#include "rtda/heap/class.h"
#include "classfile/class_file.hpp"

namespace jvm {
namespace heap {

class Class;
class ClassRef;
class FieldRef;
class MethodRef;
class InterfaceMethodRef;

class ConstantPool {
private:
    std::shared_ptr<Class> m_pClass;
    std::vector<std::shared_ptr<void>> m_consts;// ?

public:
    ConstantPool(std::shared_ptr<Class> pClass, const classfile::ConstantPool& cfCp);
    
    template<typename T>
    T getConstant(uint index) const {
        if (index >= m_consts.size() || !m_consts[index]) {
            throw std::runtime_error("No constants at index " + std::to_string(index));
        }
        return *std::static_pointer_cast<T>(m_consts[index]);
    }
};

} // namespace heap
} // namespace jvm
